<?php

namespace catchAdmin\pc\controller;

use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\pc\model\Banner as BannerModel;
use think\Response;

class Banner extends CatchController
{

    protected $bannerModel;


    /**
     *
     * @time 2025/08/15 11:36
     * @param BannerModel $bannerModel
     * @return mixed
     */
    public function __construct(BannerModel $bannerModel)
    {
        $this->bannerModel = $bannerModel;
    }


    /**
     *
     * @time 2025/08/15 11:36
     * @return Response
     */
    public function index(): Response
    {
        return CatchResponse::paginate($this->bannerModel->getList());
    }


    /**
     *
     * @time 2025/08/15 11:36
     * @param Request $request
     * @return Response
     */
    public function save(Request $request): Response
    {
        return CatchResponse::success($this->bannerModel->saveData($request->post()));
    }


    /**
     *
     * @time 2025/08/15 11:36
     * @param $id
     * @return Response
     */
    public function read($id): Response
    {
        return CatchResponse::success($this->bannerModel->findBy($id));
    }


    /**
     *
     * @time 2025/08/15 11:36
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update($id, Request $request): Response
    {
        $param = $request->post();
        $param['id'] = $id;

        return CatchResponse::success($this->bannerModel->saveData($param));
    }


    /**
     *
     * @time 2025/08/15 11:36
     * @param $id
     * @return Response
     */
    public function delete($id): Response
    {
        return CatchResponse::success($this->bannerModel->deleteBy($id));
    }
}
